package org.wattdepot.cli;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
//import org.wattdepot.resource.source.jaxb.Source;

/**
 * Simple tests of the CommmandLineInterface package. 
 * @author wattdepot-cli-ewalu
 *
 */
public class TestCommandLineInterface {
  
  /**
   * Tests the ExtractionInterface methods. 
   * @throws Exception If problems occur. 
   */
  @Test
  public void testExtractionInterface() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    String sources = cli.getSourcesInfo();
    assertTrue("Checking sources", sources.contains("AES"));
  }
  
  /**
   * Test the ExtractionInterface getPerson() method to return owner.
   * @throws Exception If problems occur.
   */
  @Test
  public void testGetPerson() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    String owner = cli.getPerson("SIM_KAHE");
    assertTrue("Checking owner", owner.contains("oscar@wattdepot.org"));
  }
  
  /**
   * Tests the StringInterface methods.
   * @throws Exception If problems occur.
   */
  @Test
  public void testStringInterface() throws Exception {
    StringInterface test = new StringExtraction("quit");
    assertTrue("Check returned argument(s)", test.parse().contains("quit"));
  }
  
  /**
   * Test an actual command input to get correct argument.
   * @throws Exception If problems occur.
   */
  @Test
  public void testUserInput() throws Exception {
    StringInterface test = new StringExtraction("list summary SIM_KAHE");
    assertNull("Check returned argument(s)",test.parse());
  }
  
  /**
   * Test the Command class that implements both ExtractionInterface and StringInterface.
   * @throws Exception If problems occur.
   */
  @Test
  public void testCommand() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    StringInterface string = new StringExtraction("list summary SIM_KAHE_1");
    String source = string.parse();
    String reply = cli.getSubSource(source);
    assertTrue("Check to make sure it pass", reply.contains("None."));
  }
  
  /**
   * Test argument returns from StringExtraction class.
   * @throws Exception If problems occur. 
   */
  @Test
  public void testHelpQuit() throws Exception {
    StringInterface string = new StringExtraction("list sources");
    assertTrue("Check stored argument is correct", string.getInput().matches("list sources"));
  }

  /**
   * Test to see if getMax function returns the largest value in the list.
   * @throws Exception If problems occur.
   */
  @Test
  public void testGetMax() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    List<Double> list = new ArrayList<Double>();
    list.add(500.0);
    list.add(750.0);
    list.add(5.0);
    list.add(1500.0);
    list.add(45.0);
    list.add(982.0);
    assertTrue("Check to make sure getMax works", cli.getMax(list).equals(1500.0));
  }
  
  /**
   * Test to see if getMin function returns the smallest value in the list.
   * @throws Exception If problems occur.
   */
  @Test
  public void testGetMin() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    List<Double> list = new ArrayList<Double>();
    list.add(200.0);
    list.add(345.0);
    list.add(12.0);
    list.add(4000.0);
    list.add(8.0);
    list.add(91982.0);
    assertTrue("Check to make sure getMin works", cli.getMin(list).equals(8.0));
  }
  
  /**
   * Test to see if getMin function returns the smallest value in the list.
   * @throws Exception If problems occur.
   */
  @Test
  public void testGetAverage() throws Exception {
    ExtractionInterface cli = new DataExtraction();
    List<Double> list = new ArrayList<Double>();
    list.add(200.0);
    list.add(400.0);
    list.add(50.0);
    list.add(4000.0);
    list.add(30.0);
    list.add(300.0);
    assertTrue("Check to make sure getAverage works", cli.getAverage(list).equals(830.0));
  }
  
}
